package day02;

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by MGL on 2017/4/3.
 */
public class Test04 {
    private static int lowbit(int index) {
        return index & -index;
    }

    private static void add(int index, int num, int[] tree) {
        while (index <= tree.length) {
            tree[index] += num;
            index += lowbit(index);
        }
    }

    private static int getSum(int index, int[] tree) {
        int sum = 0;
        while (index != 0) {
            sum += tree[index];
            index -= lowbit(index);
        }
        return sum;
    }

    public static void main(String[] args) {
        int[] tree = new int[9];
        Scanner sc = new Scanner(System.in);
        for (int i = 1; i <= 8; i++) {
            int num = sc.nextInt();
            add(i, num, tree);
        }
        System.out.println(Arrays.toString(tree));
        System.out.println(getSum(8, tree));

    }
}
